//
//  SignInInfoView.m
//  MobileOffice
//
//  Created by jjkj on 16/12/5.
//  Copyright © 2016年 liaoningjujin. All rights reserved.
//

#import "SignInInfoView.h"

@implementation SignInInfoView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame titleArr:(NSArray *)titleArr titleStr:(NSAttributedString *)titleStr{
    if (self=[super initWithFrame:frame]) {
        self.backgroundColor=[UIColor clearColor];
//        self.infoModel=infoModel;
        self.dataArr=titleArr;
        //        CGFloat viewHeight=listModel.dataArr.count*50;
        //        if (viewHeight<250) {
        //            viewHeight=250;
        //        }else if (viewHeight>IPHONE_HEIGHT-100){
        //            viewHeight=IPHONE_HEIGHT-100;
        //        }
        
        UIButton *backView=[[UIButton alloc]initWithFrame:frame];
        backView.backgroundColor=[UIColor blackColor];
        backView.alpha=0.4;
        [backView addTarget:self action:@selector(removeViewClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:backView];
        
        //        //点击手势
        //        UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(TwoTapGestureRecognizer:)];
        //        tapGesture.delegate=self;
        //        [tapGesture setNumberOfTapsRequired:1];
        //        [tapGesture setNumberOfTouchesRequired:1];
        //        [backView addGestureRecognizer:tapGesture];
        
        //创建列表
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(50, (IPHONE_HEIGHT-(_dataArr.count*64+70))/2, IPHONE_WIDTH-50*2, _dataArr.count*64+70) style:UITableViewStylePlain];
        _tableView.layer.masksToBounds=YES;
        _tableView.layer.cornerRadius=8;
        //_myTableView.backgroundColor=[UIColor redColor];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        _tableView.tag=110;
        _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        _tableView.showsVerticalScrollIndicator=NO;
        _tableView.showsHorizontalScrollIndicator=NO;
        _tableView.bounces=NO;
        //[self addTableViewUpdateRefresh:_tableView BindingIdentity:@""];
        //    [self addTableViewLoadMoreData:_tableView BindingIdentity:@""];
        [self addSubview:_tableView];
        
        //头视图
        UIView *headView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, _tableView.width, 70)];
        headView.backgroundColor=[UIColor whiteColor];
        
//        //设置富文本
//        NSString *str2 = ti;
//        NSMutableAttributedString *str3 = [[NSMutableAttributedString alloc] initWithString: str2]; //创建一个NSMutableAttributedString
//        [str3 addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(1,  titleStr.length)]; // 关键步骤，设置指定位置文字的颜色
//        [str3 addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20.0f] range:NSMakeRange(1,titleStr.length)]; //关键步骤，设置指定位置文字的字号大小
        
        UILabel *titleLabel=[[UILabel alloc]initWithFrame:CGRectMake(8, 20, _tableView.width-16, headView.height-20)];
        titleLabel.numberOfLines=0;
        titleLabel.font=[UIFont boldSystemFontOfSize:20];
        titleLabel.textColor=COLOR_MIDBLUE;
        titleLabel.textAlignment=NSTextAlignmentCenter;
        titleLabel.attributedText=titleStr;
        titleLabel.height=[LZXHelper textHeightFromTextString:titleStr.string width:titleLabel.width fontSize:20]+3;
        [headView addSubview:titleLabel];
        
        headView.height=titleLabel.height+40;
        _tableView.y=(IPHONE_HEIGHT-(_dataArr.count*64+headView.height))/2;
        _tableView.height=_dataArr.count*64+headView.height;
        _tableView.tableHeaderView=headView;
        
        UILabel *lineLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, headView.height-1, _tableView.width, 1)];
        lineLabel.backgroundColor=BACKCOLOR_GRAY;
        [headView addSubview:lineLabel];
        

        
        
    }
    return self;
}

#pragma mark - TableViewDelagate

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArr.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    //公出 异常
    NSString *cellID=@"DutyListTableViewCell";
    DutyListTableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell=[[DutyListTableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
        cell.selectionStyle=UITableViewCellSelectionStyleDefault;
        cell.myTitle.x=8;
        cell.myTitle.width=_tableView.width-16;
        cell.myTitle.textAlignment=NSTextAlignmentCenter;
        cell.myTitle.textColor=COLOR_MIDBLUE;
        cell.myTitle.font=FONT_17;
    }
    //只有最后一行为灰色
    if (indexPath.row==_dataArr.count-1) {
        cell.myTitle.textColor=[UIColor grayColor];
    }else{
        cell.myTitle.textColor=COLOR_MIDBLUE;
    }
    cell.myTitle.text=_dataArr[indexPath.row];
    return cell;
}

//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    if (_myBlock) {
//        _myBlock(_dataArr[indexPath.row]);
//        [self removeFromSuperview];
//    }
//}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 64;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row==0) {
        if (_nowBlock) {
            _nowBlock();
        }
    }else if (indexPath.row==1){
        if (_laterBlock) {
            _laterBlock();
        }
    }
    //else{
        [self removeViewClick];
    //}
}

- (void)removeViewClick{
    [self removeFromSuperview];
}

@end
